﻿using System;
class MathSum
{
    static void Main()
    {
        int numbern;
        int numberx;
        double numerator = 1d;
        double denominator = 1d;
        double sum = 1d;
        Console.WriteLine("Please input numbers N and X: ");
        do
        {
            while (true)
            {
                try
                {
                    numbern = int.Parse(Console.ReadLine());
                    break;
                }
                catch (Exception)
                {
                    Console.Write("Please re-enter number:");
                }
            }
            while (true)
            {
                try
                {
                    numberx = int.Parse(Console.ReadLine());
                    break;
                }
                catch (Exception)
                {
                    Console.Write("Please re-enter number:");
                }
            }
        } while ((numbern < 0) || (numberx < 0));
        for (int i = 1; i <= numbern; i++)
        {
            numerator = 1;
            denominator = denominator * numberx;
            for (int k = 1; k <= i; k++)
            {
                numerator = numerator * k;
            }
            sum = sum + (numerator / denominator);
            Console.WriteLine("{0}, {1}, {2}", numerator, denominator, sum);
        }
        Console.WriteLine("Number N is: {0}", numbern);
        Console.WriteLine("Number X is: {0}", numberx);
        Console.WriteLine("The sum of 1 + (1!/X) + (2!/X^2) + ... + (N!/X^N) is: {0:F6}", sum);
        Console.ReadLine();
    }
}

